import { Controller, Get } from '@nestjs/common';
import { ComExcelToolService } from './com-excel-tool.service';

@Controller('com-excel-tool')
export class ComExcelToolController {
  constructor(private readonly _comExcelToolService: ComExcelToolService) {}

  @Get('test-excel')
  async exportExcel() {
    let url;
    try {
      // 示例数据
      const chineseHeaders = ['年龄', '姓名', '邮箱'];
      const dataList = [
        { name: 'John Doe', age: 30, email: 'john.doe@example.com' },
        { name: 'Jane Smith', age: 25, email: 'jane.smith@example.com' },
        { name: 'Sam Brown', age: 22, email: 'sam.brown@example.com' },
      ];

      // 生成文件名
      const fileName = `测试.xlsx`;

      // 排序数组
      const sortArr = ['age', 'name', 'email'];

      // 调用服务层方法
      url = await this._comExcelToolService.createStyledExcel(chineseHeaders, dataList, fileName, 'TEST', sortArr);
    } catch (error) {
      console.log(error);
    }

    return { url };
  }
}
